package com.easy.generator.java;

import com.easy.generator.Easy;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;

/**
 * @author easy
 * @date 2025年07月05日 19:36
 */
public class POMGenerator {
    private static final String FILE_NAME = "pom.xml";
    private static final String GROUP_ID = Easy.GROUP_ID;
    private static final String ARTIFACT_ID = Easy.ARTIFACT_ID;
    private static final String CLASS_TEMPLATE =
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                            "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
                            "         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
                            "         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" +
                            "    <modelVersion>4.0.0</modelVersion>\n" +
                            "\n" +
                            "    <groupId>"+GROUP_ID+"</groupId>\n" +
                            "    <artifactId>"+ARTIFACT_ID+"</artifactId>\n" +
                            "    <version>"+ Easy.VERSION+"</version>\n"+
                            "    <packaging>jar</packaging>\n" +
                            "    <parent>\n" +
                            "        <groupId>org.springframework.boot</groupId>\n" +
                            "        <artifactId>spring-boot-starter-parent</artifactId>\n" +
                            "        <version>3.1.0</version> <!-- 使用Spring Boot 3.x -->\n" +
                            "    </parent>\n" +
                            "    <properties>\n" +
                            "        <maven.compiler.source>17</maven.compiler.source>\n" +
                            "        <maven.compiler.target>17</maven.compiler.target>\n" +
                            "        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n" +
                            "        <java-version>17</java-version>\n" +
                            "        <springboot-version>3.4.4</springboot-version>\n" +
                            "        <lombok-version>1.18.38</lombok-version>\n" +
                            "        <mybatis-plus-version>3.5.12</mybatis-plus-version>\n" +
                            "        <hutool-version>5.8.22</hutool-version>\n" +
                            "        <mysql-version>8.3.0</mysql-version>\n" +
                            "        <slf4j.version>2.0.9</slf4j.version>\n" +
                            "        <asm.version>9.6</asm.version>\n" +
                            "        <mybatis-plus.version>3.5.3.1</mybatis-plus.version>\n" +
                            "        <mybatis-plus-join.version>1.5.1</mybatis-plus-join.version>\n" +
                            "    </properties>\n" +
                            "    <dependencies>\n" +
                            "   <!--     <dependency>\n" +
                            "            <groupId>com.baomidou</groupId>\n" +
                            "            <artifactId>mybatis-plus-boot-starter</artifactId>\n" +
                            "            <version>3.5.12</version>\n" +
                            "        </dependency>-->\n" +
                            "        <dependency>\n" +
                            "            <groupId>com.baomidou</groupId>\n" +
                            "            <artifactId>mybatis-plus-boot-starter</artifactId>\n" +
                            "            <version>${mybatis-plus.version}</version>\n" +
                            "        </dependency>\n" +
                            "        <dependency>\n" +
                            "            <groupId>com.github.yulichang</groupId>\n" +
                            "            <artifactId>mybatis-plus-join-boot-starter</artifactId>\n" +
                            "            <version>${mybatis-plus-join.version}</version>\n" +
                            "        </dependency>\n" +
                            "        <dependency>\n" +
                            "            <groupId>com.baomidou</groupId>\n" +
                            "            <artifactId>mybatis-plus-jsqlparser</artifactId>\n" +
                            "            <version>3.5.12</version>\n" +
                            "        </dependency>\n" +
                            "        <dependency>\n" +
                            "            <groupId>org.springframework.boot</groupId>\n" +
                            "            <artifactId>spring-boot-starter-web</artifactId>\n" +
                            "        </dependency>\n" +
                            "        <dependency>\n" +
                            "            <groupId>com.mysql</groupId>\n" +
                            "            <artifactId>mysql-connector-j</artifactId>\n" +
                            "            <version>8.3.0</version>\n" +
                            "            <scope>runtime</scope>\n" +
                            "        </dependency>\n" +
                            "        <dependency>\n" +
                            "            <groupId>org.projectlombok</groupId>\n" +
                            "            <artifactId>lombok</artifactId>\n" +
                            "            <version>1.18.38</version>\n" +
                            "            <scope>provided</scope>\n" +
                            "        </dependency>\n" +
                            "        <dependency>\n" +
                            "            <groupId>cn.hutool</groupId>\n" +
                            "            <artifactId>hutool-all</artifactId>\n" +
                            "            <version>5.8.22</version>\n" +
                            "        </dependency>\n" +
                            "    </dependencies>\n" +
                            "\n" +
                            "    <build>\n" +
                            "        <plugins>\n" +
                            "            <plugin>\n" +
                            "                <groupId>org.springframework.boot</groupId>\n" +
                            "                <artifactId>spring-boot-maven-plugin</artifactId>\n" +
                            "            </plugin>\n" +
                            "        </plugins>\n" +
                            "    </build>\n" +
                            "</project>";
    public static void generateUtil() throws IOException {
        String content = String.format(CLASS_TEMPLATE, LocalDate.now());
        File outputFile = new File(Easy.PROJECT_ABSOLUTE_URL + "/" + FILE_NAME);
        try (FileWriter writer = new FileWriter(outputFile)) {
            writer.write(content);
        }
    }
    public static void generate() throws IOException {
        generateUtil();
    }

}
